package com.jzr.bedside.presenter.impl

import com.jzr.bedside.api.Api
import com.jzr.bedside.base.BasePresenter
import com.jzr.bedside.bean.BedInfoBean
import com.jzr.bedside.bean.DeviceInfoBean
import com.jzr.bedside.bean.MediaListBean
import com.jzr.bedside.presenter.contract.MultimediaActivityContract
import rx.Observer
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers

class MultimediaActivityImpl : BasePresenter<MultimediaActivityContract.View>(),
    MultimediaActivityContract.Presenter<MultimediaActivityContract.View> {


    override fun getMediaList(vararg query: String?) {
        addSubscrebe(
            Api.getInstance()?.getMediaList(*query)
                ?.observeOn(AndroidSchedulers.mainThread())
                ?.subscribeOn(Schedulers.io())
                ?.unsubscribeOn(Schedulers.io())
                ?.subscribe(object : Observer<MediaListBean?> {
                    override fun onCompleted() {}
                    override fun onError(e: Throwable) {
                        dismissLoadingDialog()
                        if (mView != null) mView?.showError(e.toString())
                    }
                    override fun onNext(t: MediaListBean?) {
                        dismissLoadingDialog()
                        if (mView != null && t != null && t.code == 0 ) {
                            mView?.getMediaListSuccess(t)
                        } else {
                            mView?.showError(t?.msg)
                        }
                    }
                })
        )
    }


}